
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function isPassword(field){
  with(field)
  {
   // var reg = /^[x00-x7f]+$/;
   //    if (! reg.test(field)){
   //      alert('密码应该由字母和数字组成');
   //     return false; 
   //    }
      if (field.value.length < 6 || field.value.length > 20)
      {
        alert('密码长度为6-20个字符');return false;
      }
      return true;
  }
}

function surePassword(field1,field2){
    if (field1.value!=field2.value) 
      {alert('两次输入密码不相同');return false}
    else return true;
}
function validate_form_login(thisform)
{
with (thisform)
  {
  if(validate_required(username,"用户名不能为空!")==false)
  {username.focus();return false}
  else if(validate_required(password,"密码不能为空!")==false)
    {password.focus();return false}
  }
}

function validate_form_register(thisform)
{
with (thisform)
  {
  if(validate_required(username,"用户名不能为空!")==false)
  {username.focus();return false}
  else if(validate_required(password,"密码不能为空!")==false)
    {password.focus();return false}
  else if (validate_required(password_sure,"确认密码不能为空！")==false)
   {email.focus();return false}
  else if (validate_required(email,"邮箱不能为空!")==false)
   {email.focus();return false}
  else if (isPassword(password)==false) 
   {password.focus();return false}
 else if (surePassword(password,password_sure)==false) 
  {password_sure.focus();return false}
  else if (validate_email(email,"请输入正确的邮箱地址")==false)
   {email.focus();return false}
   }
}
